package foo.bar.wiki.web.action.general;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.extension.PageTypeConverter;
import foo.bar.wiki.web.nonextension.RomeSyndicationResolution;
import foo.bar.wiki.services.FeedType;
import foo.bar.wiki.services.FeedsService;
import foo.bar.wiki.domain.Page;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.EnumeratedTypeConverter;
import net.sourceforge.stripes.integration.spring.SpringBean;
import com.sun.syndication.feed.synd.SyndFeed;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class PageFeedActionBean extends BaseActionBean {


    @Validate(converter = PageTypeConverter.class)
    private Page page;

    @Validate(converter = EnumeratedTypeConverter.class)
    private FeedType feedType = FeedType.rss_2_0;

    private FeedsService feedsService;


    @DefaultHandler
    public Resolution view() {
        SyndFeed feed = feedsService.producePageFeeds(page, feedType);
        return new RomeSyndicationResolution(feed);
    }


    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public FeedType getFeedType() {
        return feedType;
    }

    public void setFeedType(FeedType feedType) {
        this.feedType = feedType;
    }

    @SpringBean("feedsService")
    public void setFeedsService(FeedsService feedsService) {
        this.feedsService = feedsService;
    }
}
